package com.polaris.live.viewmodel.backpack

import androidx.lifecycle.MutableLiveData
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.network.request
import com.polaris.live.common.network.state.ResultState
import com.polaris.live.net.payerService
import com.polaris.live.resp.back_resp.PayerShopResp
import com.polaris.live.resp.base.ListResp
import com.polaris.live.widget.refresh.OnListListener

/**
 *
 * @author Created by 天晴 on 2024/7/22 13:55
 * @since 1.0.0
 **/
class CommodityModel : BaseViewModel(), OnListListener {

    val shopListLiveData = MutableLiveData<ResultState<ListResp<PayerShopResp>>>()

    val pageSize = 20  // 每页记录数
    private val shopType = 0
    private var objectType = 0

    private fun getShop(pageNumber: Int, pageSize: Int = this.pageSize) {
        request({ payerService.getShopList(shopType, objectType, pageNumber, pageSize) }, shopListLiveData)
    }

    override fun onRefresh() {
        getShop(pageNumber = 0)
    }

    override fun onLoadMore(pageIndex: Int) {
        getShop(pageNumber = pageIndex)
    }

    fun setObjectType(type: Int) {
        objectType = type
    }
}